package cloud.tianai.ram.policy.server.autoconfiguration;

import cloud.tianai.ram.policy.common.handler.ActionHandler;
import cloud.tianai.ram.policy.common.handler.ConditionHandlerManager;
import cloud.tianai.ram.policy.common.handler.PermissionHandler;
import cloud.tianai.ram.policy.common.handler.ResourceHandler;
import cloud.tianai.ram.policy.server.action.impl.AntActionHandler;
import cloud.tianai.ram.policy.server.condition.impl.SpringConditionHandlerManager;
import cloud.tianai.ram.policy.server.permission.impl.SpringPermissionHandler;
import cloud.tianai.ram.policy.server.resource.impl.AntResourceHandler;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: 天爱有情
 * @date 2022/3/23 16:43
 * @Description Ram server 自动装配器
 */
@Configuration
public class RamServerAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public ConditionHandlerManager conditionHandlerManager(BeanFactory beanFactory) {
        return new SpringConditionHandlerManager(beanFactory);
    }

    @Bean
    @ConditionalOnMissingBean
    public ActionHandler actionHandler() {
        return new AntActionHandler();
    }

    @Bean
    @ConditionalOnMissingBean
    public ResourceHandler resourceHandler() {
        return new AntResourceHandler();
    }

    @Bean
    @ConditionalOnMissingBean
    public PermissionHandler permissionHandler(BeanFactory beanFactory) {
        return new SpringPermissionHandler(beanFactory);
    }
}
